package test.top1.com.atguigu.utils;

import lombok.SneakyThrows;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
import org.apache.flink.util.Collector;
import test.top1.com.atguigu.bean.TradeSkuOrderBean;

import java.lang.reflect.Field;

/**
 * ClassName: WindowFunctionUtil
 * Package: test.top1.com.atguigu.utils
 * Description:
 *
 * @Author ChenJun(有志男青年)
 * @Create 2023/5/10 18:36
 * @Version 1.0
 */
public class WindowFunctionUtil {

    @SneakyThrows
    public static <T> void set(Iterable<T> values, TimeWindow window, Collector<T> out){

        T next = values.iterator().next();

        Class<?> aClass = next.getClass();

        Field ts = aClass.getDeclaredField("ts");
        ts.setAccessible(true);
        ts.set(next,System.currentTimeMillis());

        Field stt = aClass.getDeclaredField("stt");
        stt.setAccessible(true);
        stt.set(next,DateFormatUtil.toYmdHms(window.getStart()));

        Field edt = aClass.getDeclaredField("edt");
        edt.setAccessible(true);
        edt.set(next,DateFormatUtil.toYmdHms(window.getEnd()));

        out.collect(next);

        //
        //BeanUtils.setProperty(next,"ts",System.currentTimeMillis());



    }
}
